Talk:Combining data models from regular Java classes
This is an important topic Pforhan 21:39, 18 May 2007 (UTC) We need to develop this into a full-fledged article discussing the problem, then a tutorial describing how to make things work the way we want, and then a framework encapsulating best practices, hopefully. Perhaps Chaotic Java can provide content for a start? I have a very poorly implemented communication layer implemented currently, which could serve as a springboard for a tutorial. :Right now, there is no binding available back to java objects or vice-versa. I think PropertyChangeListeners are probably the way to go, on both sides. On the JFX side, I guess a person could use triggers to invoke behavior to write back to the comm object... :I've looked at the code, but couldn't understand it too well - Presumably because I am not familiar with the framework you are using (for example, where are the listeners being called to be notified of a change in say, the Selected property?). I do think that an option of using some form of AOP should be considered, to make it easier to bind current data models to JFX - otherwise, people will not be so easy on switching from whatever they're using now to JFX, no matter how good it might look. --Aviadbd 21:59, 18 May 2007 (UTC) :What framework? ;-) Really, it was just a proof of concept. From java, the only thing I update is the array of Objects. After that, I fire a changeEvent to the only listener -- in this case, the JFX script. The only time code comes back into Java-land from JFX land is when the button is pressed. At that time, selected is updated, and provisionRequested is invoked. Like I said, very rough. :So, we could set up a trigger on the model inside jfx, and call javaModel.setSelected each time it changes, then fire an event to the java code... but anyway, still not overly pretty. I think the big problem here is that we still don't have any binding, even one-way, back into java objects. --Pforhan 22:17, 18 May 2007 (UTC) :Oh. I guess I was looking at it as if it's a way to notify the JFX elements of a change in the Java objects, which might occur as business rules takes place behind the scenes. But it's obvious that a two-way binding is required, and required to be done easily enough to get people to use this. I suggest we start by making a general concept scaffold of how to make a two-way binding between JFX and Java. Once we do that, we can start thinking AOP, Code Enhancement, Annotations using APT, or anything else. --Aviadbd 22:31, 18 May 2007 (UTC) :Okay, I think I understand your example better now. However, the problem I see with it is that it encapsulates the Java model's members and not the instance itself. What I mean is, that if I had a class Person and wanted to encapsulate it inside a PersonUI, I would expect to do this: class PersonUI extends CompositeNode { attribute x: Number; attribute y: Number; attribute person: Person; } operation PersonUI.composeNode() = Text { x: bind x y: bind y text: bind person.name } :However, I cannot since it will tell me Person is not a valid object (at least in the NB 6.0m9 plug-in). In your example, you used an instance (using var) of the model and then used binding on its properties, but that's surely not the recommended way! --Aviadbd 13:55, 19 May 2007 (UTC) ::Yes, I had created a model explicitly for talking to JavaFX. I was not trying to supply a different model. Do you think that will be too hard? I have to wonder if we should consider a pure data-driven model to work from at first, and just make adapters on both sides... :::I think that it will be natural and intuitive to users of JavaFX, especially ones migrating to it from other frameworks such as GWT or Swing, to allow the usage of old data-models. More so because there are probably business logic running on those data models, and JavaFX will be used only to reflect the data and the changes in it. --Aviadbd 14:21, 21 May 2007 (UTC) ::::Oh, I would like to do it, I just don't know how easy it is. Perhaps we should split into two tracks, one for models made with JavaFX in mind, and another for legacy models. --Pforhan 14:40, 21 May 2007 (UTC) :::::I agree that we have two different problems: First, how to communicate between Java properties and JavaFX attributes, and the second is how to use pure data-models as a JavaFX attribute, and bind to their properties (using the same way used in the first problem, to keep it simple). I do think these two are the same topic, namely the combination of Java data models into JavaFX applications. --Aviadbd 15:16, 21 May 2007 (UTC) :::::Also, we might be walking on a road that has been passed through before. Since there is no documentation (yet) to the project, there already might be a solution or a plan for a solution in the road map (which is also in need of definition). I think we should also get the input of Chris about this, being the JFX-Guru and all. --Aviadbd 15:19, 21 May 2007 (UTC) From a strictly-Java viewpoint, here are some projects that should be examined: #JSR-295 is in progress and about Swing Beans-Binding, so that would be highly relevant. #The "Bean Properties" project on java.net provides some great mechanisms for writing beans that are very binding friendly. #"Glazed Lists" provides binding-friendly bean collections. Mailing list posting... Pforhan 20:09, 23 May 2007 (UTC) a recent mailing list posting regarding binding can be found here: https://openjfx.dev.java.net/servlets/BrowseList?list=users&by=thread&from=772173 ... I'm left with a vague sense of disappointment... :But that is not surprising. Chris is right: The change event in Swing only deals with replace triggers, and not with insert or delete. Other platforms (Silverlight, for example) just offer two types of events, one for collections and one for single-values. I suggest we come up with an interface a class needs to implement (or maybe, as they call it in Obj-C, an "informal interface" where there are naming conventions for easier implementation, or both!). Then, attach the JavaFX framework with these interfaces and allow for binding, once and for all.--Aviadbd 20:18, 23 May 2007 (UTC) :I've added a new article about this matter in my blog - Too long to post here. :) What do you think? --Aviadbd 07:21, 25 May 2007 (UTC) ::Sounds reasonablish. I think our ultimate problem is that there just is a degree of separation still. If I can't use the bind operator directly in the JFX code to hook up to our new object, we're still in a bit of trouble. Do we have a good idea of the event structure we need to set up? That is something we can do now, and is concrete. Then some solutions can make use of it, whether AOP or Dynamic Proxies or what-have-you.Pforhan 21:07, 25 May 2007 (UTC) :::Unfortunately, no. I couldn't get any answer about it... And there's no way to do it using the code, as the javafxrt.jar is not open sourced (yet?). --Aviadbd 21:17, 25 May 2007 (UTC) Observable Lists You may want to look into an observable list implementation. Apache is good, but I believe the absolute best out there for Java right now is the open source GlazedLists project.